using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Toenda.TFL.Base;
using Toenda.Rails.System;
using Toenda.Rails.DataContainer;

public partial class Controls_Admin_ctrl_deleteuser : System.Web.UI.UserControl {
	private AccountProvider ap = new AccountProvider();
	private StaticProvider sp = new StaticProvider();

	/// <summary>
	/// Page_Load
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e) {
		if(Session.Count > 0) {
			Account acc = ap.GetAccountBySession(Session["Zappr"].ToString());

			if(acc.Type == 2) {
				string param = "";

				if(Request.QueryString.Get("Search") != null) {
					param = Request.QueryString.Get("Search");
				}

				lblTitle.Text = GetLocalResourceObject("All").ToString();
				ArrayList arr = ap.GetAccounts(OrderUserBy.RegisterDateDESC, UserListAttribute.All);
				
				gvUser.DataSource = arr;
				gvUser.AllowPaging = true;
				gvUser.PagerSettings.Mode = PagerButtons.NumericFirstLast;
				gvUser.PagerSettings.PageButtonCount = 3;
				gvUser.PageSize = 25;
				gvUser.DataBind();
			}
			else {
				Response.Redirect("~/login.aspx");
			}
		}
		else {
			Response.Redirect("~/login.aspx");
		}
	}

	/// <summary>
	/// gvUser_PageIndexChanging
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void gvUser_PageIndexChanging(object sender, GridViewPageEventArgs e) {
		gvUser.PageIndex = e.NewPageIndex;
		gvUser.DataBind();
	}

	/// <summary>
	/// DeleteAccount
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void DeleteAccount(object sender, CommandEventArgs e) {
		ap.DeleteUser(e.CommandArgument.ToString());
		Response.Redirect("~/default.aspx?id=_deleteuser");
	}

	/// <summary>
	/// ActivateAccount
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void ActivateAccount(object sender, CommandEventArgs e) {
		ap.EnableUser(e.CommandArgument.ToString());
		Response.Redirect("~/default.aspx?id=_deleteuser");
	}
}
